<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul{
            list-style: none;
        }
        .one{
            margin: 50px auto;
            width: 340px;
            height: 30px;
            background: url('./bg.jpg') no-repeat;
            border-radius: 10px;
        }
        .one>li{
            float: left;
            margin-left: 10px;
            width: 100px;
            height: 30px;
            background: url('./libg.jpg') no-repeat;
            text-align: center;
            line-height: 30px;
            border-radius: 10px;
        }
        .two{
            display: none;
        }
        .two>li{
            background: url('./libg.jpg') no-repeat;
            border-radius: 10px;
        }
    </style>
</head>
<body>
    <ul class="one">
        <li>一级标签
            <ul class="two">
                <li>二级标签</li>
                <li>二级标签</li>
                <li>二级标签</li>
            </ul>
        </li>
        <li>一级标签
            <ul class="two">
                <li>二级标签</li>
                <li>二级标签</li>
                <li>二级标签</li>
            </ul>
        </li>
        <li>一级标签
            <ul class="two">
                <li>二级标签</li>
                <li>二级标签</li>
                <li>二级标签</li>
            </ul>
        </li>
    </ul>
</body>
<script>
    var onLis = document.querySelectorAll('.one>li')
    var two = document.querySelectorAll('.two')
    //为第一个ul里面的li注册一个鼠标经过事件
    onLis.forEach((item,index)=>{
        item.onmouseover = function(){
            two[index].style.display = 'block'
        }
        //注册一个鼠标离开事件，当鼠标离开时子元素ul隐藏
        item.onmouseout = function(){
            two[index].style.display = 'none'
        }
    })
</script>
</html>